#include "gd32l23x.h"
#include "stdint.h"
#include "stdio.h"
#include "DevicesExti.h"


void vExtiKeyInit(void)
{
    /* enable the key clock */
    rcu_periph_clock_enable(RCU_SYSCFG);
    rcu_periph_clock_enable(RCU_GPIOD);

    /* configure button pin as input */
    gpio_mode_set(GPIOD, GPIO_MODE_INPUT, GPIO_PUPD_NONE, GPIO_PIN_3);

    /* connect key EXTI line to key GPIO pin */
    syscfg_exti_line_config(EXTI_SOURCE_GPIOD, EXTI_SOURCE_PIN3);

    /* configure key EXTI line */
    exti_init(EXTI_3, EXTI_INTERRUPT, EXTI_TRIG_RISING);

    exti_interrupt_flag_clear(EXTI_3);

    /* enable and set key EXTI interrupt to the lowest priority */
    nvic_irq_enable(EXTI3_IRQn, 2U);
}
